package com.yzk.train.business.controller.admin;

import com.yzk.train.business.request.StationQueryReq;
import com.yzk.train.business.request.StationSaveReq;
import com.yzk.train.business.response.StationQueryResp;
import com.yzk.train.business.service.StationService;
import com.yzk.train.common.response.PageResp;
import com.yzk.train.common.response.Result;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/admin/station")
public class StationAdminController {

    @Resource
    private StationService stationService;

    @PostMapping("/save")
    public Result<Object> save(@Valid @RequestBody StationSaveReq req) {
        String message = stationService.save(req);
        return Result.ok(message);
    }

    @GetMapping("/list")
    public Result<PageResp<StationQueryResp>> queryList(@Valid StationQueryReq req) {
        PageResp<StationQueryResp> pageResp = stationService.queryList(req);
        return Result.ok(pageResp);
    }

    @GetMapping("/all")
    public Result<List<StationQueryResp>> queryAll() {
        List<StationQueryResp> list = stationService.queryAll();
        return Result.ok(list);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Object> delete(@PathVariable Long id) {
        stationService.delete(id);
        return Result.ok("删除成功");
    }

}
